#include "defectlevelmap.h"

DefectLevelMap::DefectLevelMap(QObject *parent)
    : QObject{parent}
{}

QString DefectLevelMap::GetHighLevelDefect(QList<QString> list)
{
    DefectLevel highestLevel = Level4; // 假设4是最低等级
    QString highestDefect;
    bool bMainDefect = false;//表示是否找到了主缺陷
    //   疤痕
    //  擦伤  疤痕 氧化皮
    foreach (QString defectName, list) {
        QString trimmedDefect = defectName.trimmed();
        //如果存在就替换成最高等级的缺陷否则返回他原本的名称
        if(defectLevelMap.contains(trimmedDefect)){
            DefectLevel level = defectLevelMap.value(trimmedDefect);
            if(level < highestLevel){
                highestLevel = level;
                highestDefect = trimmedDefect;
                bMainDefect = true;
            }
        }
        //如果整卷都没找到比较高等级的主缺陷 那么就随便返回一个
        if(!bMainDefect){
            highestDefect = defectName;
        }
    }
    return highestDefect;
}
